package game;
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.nio.ByteBuffer;

import javax.imageio.ImageIO;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;

import java.awt.Frame;
import java.awt.event.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;
import javax.media.opengl.glu.GLU;
import java.util.*;
import java.io.*;
import javablender.*;
import java.util.*;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;

/*
 * class ModelGen :
 */

public class ModelGen {
protected LinkedList vertices = new LinkedList();
private int padsize = 4;
private int width = 48;
private int height = 48;
private float x = 0.0f;
private float y = 0.0f;
private float z = 0.0f;


/*
 * embedded classes
 */
	protected class Vertex
	{
		protected float x,y,z;
		public Vertex(float xx, float yy, float zz)
		{
			x = xx;
			y = yy;
			z = zz;
		}

		public float getx()
		{
			return x;
		}
	
		public float gety()
		{
			return y;
		}
	
		public float getz()
		{
			return z;
		}
	
	};

/*
 * Constructors
 */	
	public ModelGen(int ww, int hh, int pad)
	{
		width = ww;
		height = hh;
		//read pad vertices at oncefor storing a polygon
		padsize = pad;
		

	}

/*
 * math functionality
 */

    public float normal(float xx1, float yy1, float zz1, float xx2, float yy2, float zz2)
    {

	return (float)Math.sqrt((float)xx1*xx2 + (float)yy1*yy2 + (float)zz1*zz2);

    } 

/*
 * drawing primitives e.g. sphere, polygons
 */


	public void generatesphere(float radius, int pieces)
	{
		padsize = 3;
		int meridians = 3*pieces;
		int parallels = 3*pieces;

		for (float theta = 0; theta < Math.PI; theta += Math.PI/meridians) {
			for (float phi = 0; phi < 2*Math.PI; phi += 2*Math.PI/parallels) {

				vertices.add(new Vertex((float)(x+Math.cos(theta)*Math.sin(phi)*radius),
							(float)(y+Math.sin(theta)*Math.sin(phi)*radius),
							(float)(z+Math.cos(phi)*radius)));		
			}	
		}
	}

/*
 * accessors
 */
	public float getvertexx(int index)
	{
		Object o = vertices.get(index);
		Vertex v = (Vertex)o;
		float xx = v.getx();
		return xx;
	} 
	public float getvertexy(int index)
	{
		Object o = vertices.get(index);
		Vertex v = (Vertex)o;
		float yy = v.gety();
		return yy;
	} 
	public float getvertexz(int index)
	{
		Object o = vertices.get(index);
		Vertex v = (Vertex)o;
		float zz = v.getz();
		return zz;
	} 

	public int size()
	{
		return vertices.size();
	}

	public int padsize()
	{
		return padsize;
	}
};
